package cn.jingdalei.user.controller;

import cn.jingdalei.basic.exception.BusinessException;
import cn.jingdalei.basic.util.AjaxResult;
import cn.jingdalei.user.service.IVerifyCodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 参数很少的情况使用
     * 一定情况下map可以代替对象接收参数【map也可以看成一个对象】
     *
     * @param param
     * @return
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody Map<String, String> param) {
        try {
            verifyCodeService.smsCode(param);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统繁忙，请稍后重试");
        }
    }
}
